package org.aeon.gamechatnest.util;

import org.aeon.gamechatnest.exception.ApplicationException;
import org.aeon.gamechatnest.exception.TargetIsAnEmptyException;

import java.util.Objects;

/**
 * @author: MissingAeon
 * @date: 2024/5/11 13:46
 * @description: 断言 用于快速判断应用的运行结果
 */
public class ApplicationAssert {

    public static void isSuccess(boolean condition, ApplicationException e) throws ApplicationException {
        if (!condition) {
            throw e;
        }
    }

    public static void isSuccess(boolean condition, String message) throws ApplicationException {
        if (!condition) {
            throw new ApplicationException(message);
        }
    }

    public static void isSuccess(boolean condition) throws ApplicationException {
        if (!condition) {
            throw new ApplicationException();
        }
    }

    public static void nonNull(Object object, String message) throws TargetIsAnEmptyException {
        if (Objects.isNull(object)) {
            throw new TargetIsAnEmptyException(message);
        }
    }

    public static void nonNull(Object object) throws TargetIsAnEmptyException {
        if (Objects.isNull(object)) {
            throw new TargetIsAnEmptyException("参数错误！");
        }
    }
}
